package com.jnu.myllm.ui;

import com.jnu.myllm.entity.User;
import com.jnu.myllm.server.RecordService;
import com.jnu.myllm.ui.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@CrossOrigin(origins = "*")
@RestController
public class RecordController {
    @Autowired
    private RecordService recordService;
    @GetMapping("/record/list")
    public Result selectByUser(HttpServletRequest request)
    {
        // 从jwt解析用户id
        User user = (User) request.getAttribute("user");
        return new Result(2000, "success", recordService.selectByUser(user.getId()));
    }
    @GetMapping("/record/count")
    public Result selectCountByToday(HttpServletRequest request)
    {
        User user = (User) request.getAttribute("user");
        int count = recordService.queryCountByToday(user.getId());
        return new Result(2000, "success", count);
    }
}
